/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kimstore.utilities;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author wednesday
 */
public class Encryption {
    
        private static StringBuilder sb = new StringBuilder();

    public static String sha(String password){
        try {

            sb.setLength(0);
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(password.getBytes());

            byte byteData[] = md.digest();

            //convert the byte to hex format method 1
            for (int i = 0; i < byteData.length; i++) {
             sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }

            
            //convert the byte to hex format method 2
//            StringBuilder hexString = new StringBuilder();
//                for (int i=0;i<byteData.length;i++) {
//                        String hex=Integer.toHexString(0xff & byteData[i]);
//                            if(hex.length()==1) hexString.append('0');
//                            hexString.append(hex);
//                }
//                System.out.println("Hex format : " + hexString.toString());
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex);
        }
        return (sb.toString());
    }
    
}
